package com.woniuxy.creditsystem.applymag.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.creditsystem.applymag.service.IApplyService;
import com.woniuxy.creditsystem.common.bean.*;

import com.woniuxy.creditsystem.common.util.PageRest;
import com.woniuxy.creditsystem.common.util.ResultMsg;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;

/**
 * @author ：zhengbin
 * @date ：Created in 2020/12/12
 * @description：
 * @modified By：
 * @version: $
 */

@RequestMapping("apply")
@RestController
public class ApplyController {

    @Resource
    private IApplyService applyServiceImpl;


    @ResponseBody
    @GetMapping(value = "/all",produces = "application/json;charset=utf-8")
    public ResultMsg<List<DtoApply>> findAll(){

        ResultMsg<List<DtoApply>>  resultMsg = new ResultMsg();
        System.out.println("all............");
        List<DtoApply> lists= applyServiceImpl.findAll();
        System.out.println("查询结果");
       System.out.println(lists);
        resultMsg.setData(lists);
        resultMsg.setCode(200);
        resultMsg.setMsg("操作成功");
        return  resultMsg;

    }


    @ResponseBody
    @GetMapping(value = "/one",produces = "application/json;charset=utf-8")
    public ResultMsg findOneById(@RequestParam("aid")long id){
        System.out.println("id:"+id);
        ResultMsg<ApplyInfo> resultMsg = new ResultMsg<ApplyInfo> ();
        resultMsg.setData(applyServiceImpl.findById(id));
        resultMsg.setCode(200);



        return resultMsg;

    }

    //分页查询
    @ResponseBody
    @GetMapping(value = "/page",produces = "application/json;charset=utf-8")
    public TableResult<DtoApply> findByParams(PageRest pageRest, DtoApply dtoApply){


        System.out.println("pageRest"+pageRest);
        System.out.println(dtoApply);
        PageInfo<DtoApply> pageInfo= applyServiceImpl.findByParam(pageRest,dtoApply);
        System.out.println(pageInfo);
        System.out.println(pageInfo.getTotal());

        return new TableResult<DtoApply>(pageInfo.getTotal(),pageInfo.getList());
    }

}
